<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body></body>
  <script>
    /**
     * @params prev   累加器累计回调的返回值，它是上一次调用回调时返回的累积值
     * @params current    数组中正在处理的元素
     * @params index   正在处理元素的索引
     * @params  array    调用reduce()的数组
     * @params  initalValue    第一次调用callback函数时的第一个参数的值
     */
    var arr = [{ name: 'one' }, { name: 'two' }, { name: 'three' }];
    let res = arr.reduce(function (prev, current, index, array) {
      if (index === 0) {
        return current.name;
      } else if (index === array.length - 1) {
        return prev + '&' + current.name;
      } else {
        return prev + ',' + current.name;
      }
    }, '');
    console.log(res);
  </script>
</html>
